package com.idol.web.util;

import java.io.UnsupportedEncodingException;

/**
 * @author Supreme_Sir
 * @version 1.0
 * @className ResponseHeaderUtil
 * @description 响应头处理工具
 * @date 2020/11/16 23:41
 **/
public class ResponseHeaderUtil {
    /**
     * 为响应码200提供请求头信息
     * @return
     */
    public static String getHttpHeader200(long contentLength) throws UnsupportedEncodingException {
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html \n" +
                "Content-Length: " + contentLength + " \n" +
                "\r\n";
    }

    /**
     * 为响应码404提供请求头信息(此处也包含了数据内容)
     * @return
     */
    public static byte[] getHttpHeader404() throws UnsupportedEncodingException {
        String str404 = "<h1>404 not found</h1>";
        return ("HTTP/1.1 404 NOT Found \n" +
                "Content-Type: text/html \n" +
                "Content-Length: " + str404.getBytes("GBK").length + " \n" +
                "\r\n" + str404).getBytes("GBK");
    }
}
